//
//  WBStatusModel.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/13.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "WBStatusModel.h"
#import "WBUserModel.h"
#import "WBPictureInfo.h"


@implementation WBStatusModel

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    if(self = [super init])
    {
        
        [self setValuesForKeysWithDictionary:dict];
    
    }
    return self;
}

- (void)setValue:(id)value forKey:(NSString *)key
{
    if([key isEqualToString:@"user"])
    {
        
        //创建模型
        WBUserModel *model = [WBUserModel userModelWithDictionary:value];
        
        self.user = model;
    
    }else if ([key isEqualToString:@"retweeted_status"])
    {
        
        self.retweeted_status = [WBStatusModel statusModelWithDictionary:value];

    }else if ([key isEqualToString:@"pic_urls"]){
        
        //这是配图字段 返回是一个数组 数组里面存储的是字典  我们要面向模型开发 所以要字典转模型
        
        //创建可变数组
        NSMutableArray *tempArrM = [NSMutableArray array];
        
        //遍历数组
        for (NSDictionary *dict in value) {
            
            WBPictureInfo *model = [WBPictureInfo pictureInfoWithDictionary:dict];

            //添加到临时数组中
            [tempArrM addObject:model];
            
        }
    
        //赋值
        self.pic_urls = tempArrM.copy;
    
    }
    else if ([key isEqualToString:@"id"])
    {
        
        //因为是关键字
        self.sinaId = [(NSNumber *)value integerValue];
        
        
    
    }else{
        [super setValue:value forKey:key];
    
    }

}


//防止KVC报错
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{

}

+ (instancetype)statusModelWithDictionary:(NSDictionary *)dict
{

    return [[self alloc] initWithDictionary:dict];

}

@end
